"""
检查用户账户
"""
import asyncio
from app.core.database import init_db
from app.models.user import User
from app.utils.security import verify_password

async def main():
    """检查用户账户"""
    try:
        print("🔧 连接数据库...")
        await init_db()
        
        print("🔍 查找admin用户...")
        admin_user = await User.get_or_none(username="admin")
        
        if admin_user:
            print(f"✅ 找到用户: {admin_user.username}")
            print(f"   邮箱: {admin_user.email}")
            print(f"   是否激活: {admin_user.is_active}")
            print(f"   是否超级用户: {admin_user.is_superuser}")
            print(f"   密码哈希: {admin_user.hashed_password[:50]}...")
            
            # 测试密码验证
            print("\n🔍 测试密码验证...")
            is_valid = verify_password("admin123", admin_user.hashed_password)
            print(f"密码验证结果: {'✅ 正确' if is_valid else '❌ 错误'}")
            
        else:
            print("❌ 未找到admin用户")
            
            # 列出所有用户
            print("\n🔍 列出所有用户...")
            all_users = await User.all()
            for user in all_users:
                print(f"  - {user.username} ({user.email})")
        
    except Exception as e:
        print(f"❌ 检查失败: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    asyncio.run(main())
